//src/client/pages/index/index.js
//index 组件
import React from 'react';
import { Helmet } from 'react-helmet';
import './index.scss';
import PageContainer from '../../common/components/page-container';

//组件
class Index extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count:0
      ,aaa:111
    };
  }

  handlerClick() {
    alert('一起来玩 react 服务端渲染~~');
  }

  static async getInitialProps() {
    console.log('fetch data index');
    //模拟数据请求方法
    //...

    return {
      page: {
        tdk: {
          title: '首页 - react ssr',
          keywords: '前端技术江湖',
          description: '描述'
        }
      }
    };
  }


  render() {
    console.log('this.state:',this.state)
    const {tdk={}} = this.props.initialData.page || {};
    return (
      <div className="page-index-box">
        <Helmet>
          <title>{tdk.title}</title>
          <meta name="description" content={tdk.description}/>
          <meta name="keywords" content={tdk.keywords}/>
        </Helmet>
        123首页
        {this.state.count}
        <button onClick={()=>this.setState({count: this.state.count + 1})}>+</button>
        emmm {this.state.aaa}
      </div>
    )
  }
}

export default PageContainer(Index);
